#include "ObjPtrBase.h"
#include "Object.h"

ObjPtrBase::ObjPtrBase(Object* owner, Object* ptr) :
  owner(owner), ptr(ptr)
{
	if(owner) owner->addInnerRef(this);
	if(ptr) ptr->addOuterRef(this);
}

void ObjPtrBase::operator=(Object* newPtr)
{
	if(ptr == newPtr) return;
	if(ptr) ptr->removeOuterRef(this);
	ptr = newPtr;
	if(newPtr) newPtr->addOuterRef(this);
}

ObjPtrBase::~ObjPtrBase()
{
	if(ptr) ptr->removeOuterRef(this);
}